package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Organization;
import cn.wolfcode.crm.domain.Product;
import cn.wolfcode.crm.mapper.ProductMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IProductService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class ProductServiceImpl implements IProductService {
    @Autowired
    private ProductMapper mapper;
    @Override
    public List<Product> selectAll() {
        return mapper.selectAll();
    }

    @Override
    public PageResult query(QueryObject qo) {
        int count = mapper.query4Count(qo);
        if (count > 0) {
            return new PageResult(count, mapper.query4List(qo));
        }
        return new PageResult(count, Collections.EMPTY_LIST);
    }

    @Override
    public void insert(Product record,Organization organization) {
        mapper.insert(record,organization);
    }

    @Override
    public void updateByPrimaryKey(Product dept,Organization organization) {
        mapper.updateByPrimaryKey(dept,organization);
    }

    public List<Product> selectProductByOrganizationId(Long id) {
        return mapper.selectProductByOrganizationId(id);
    }



    public Product selectByPrimaryKey(Long id) {
        return mapper.selectByPrimaryKey(id);
    }


}
